Skip to content

[taskprocessing] Add an endpoint to get the position of a scheduled task in the queue - #62414

Open
julien-nc wants to merge 1 commit into
masterfrom
enh/noid/task-queue-position-endpoint
Open

[taskprocessing] Add an endpoint to get the position of a scheduled task in the queue#62414
julien-nc wants to merge 1 commit into
masterfrom
enh/noid/task-queue-position-endpoint

Conversation

@julien-nc

@julien-nc julien-nc commented Jul 22, 2026

Copy link
Copy Markdown
Member

GET /ocs/v2.php/taskprocessing/tasks/TASK_ID/queue_position
returns the number of scheduled tasks that are older than the TASK_ID one (+1).

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@julien-nc julien-nc added this to the Nextcloud 35 milestone Jul 22, 2026
@julien-nc
julien-nc force-pushed the enh/noid/task-queue-position-endpoint branch from 559558d to 92bb9ac Compare July 24, 2026 08:34
@julien-nc julien-nc added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 24, 2026
@julien-nc
julien-nc marked this pull request as ready for review July 24, 2026 08:49
@julien-nc
julien-nc requested review from a team and provokateurin as code owners July 24, 2026 08:49
@julien-nc
julien-nc requested review from Altahrim, leftybournes and salmart-dev and removed request for a team July 24, 2026 08:49
Comment thread lib/private/TaskProcessing/Db/TaskMapper.php
}

try {
return 1 + $this->taskMapper->countPendingTasksBefore($taskEntity->getLastUpdated());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we filter by task type here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, if we think of exApps, makes sense to consider there is one queue per task type (even if some exApps implement providers for multiple task types), but with Php providers, the workers are common for all task types.

@julien-nc
julien-nc force-pushed the enh/noid/task-queue-position-endpoint branch from 92bb9ac to 6a41cfd Compare July 27, 2026 10:14
@nextcloud-bot nextcloud-bot mentioned this pull request Aug 12, 2026
…led task in the queue

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc
julien-nc force-pushed the enh/noid/task-queue-position-endpoint branch from 6a41cfd to 3d7c551 Compare August 17, 2026 08:37

@kyteinsky kyteinsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!
(nit) what do you think about using notify_push in addition to this?
for sync providers, an update can be fired in the process or claim (used by taskproc worker) function so every time a task is picked (SCHEDULED -> RUNNING), the frontend would know the queue moved, maybe there's a chance of de-sync since frontend would first get the queue position and then decrement for each update but this is not that critical I suppose.
for async providers, this can be done in the next_task function.
it would be essentially the same path as the streaming outputs.

@julien-nc

Copy link
Copy Markdown
Member Author

@kyteinsky I think we need as much reactivity as possible when displaying a task's output. But we don't need to be that fast/reactive when showing the queue info IMHO. Using notify_push here would make the assistant's UI implementation a little bit more complex for a very small gain. Wdyt?

@kyteinsky

Copy link
Copy Markdown
Contributor

I was thinking more in the performance area, this polling would be done by every user who schedules a task in assistant so could be a load on the server and db. With notify_push, it would be event based and only one php call would send out updates to all the listening users.
But it can be done in a later iteration too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants